import os 
import sys 
import getpass
import shutil


def add_path_prefix(path_str):
    """ Compatible windows-sys filepath """
    if sys.platform != "win32":
        return path_str

    if path_str.startswith("\\\\?\\"):
        return path_str

    ret = "\\\\?\\" + os.path.abspath(path_str)
    ret = ret.replace("/", "\\")
    return ret

def copy_dirfiles_to(fromdir, todir, ignorelist=[]):
    """ Copy all files from $fromdir to $todir|both path must exist! """
    for item in os.listdir(fromdir):
        path = os.path.join(fromdir, item)
        if os.path.isfile(path):
            path = add_path_prefix(path)
            copy_dst = add_path_prefix(todir)
            shutil.copy(path, copy_dst)
        if os.path.isdir(path) and todir != path:
            new_dst = os.path.join(todir, item)
            if not os.path.isdir(new_dst):
                os.makedirs(add_path_prefix(new_dst))
            copy_dirfiles_to(path, new_dst)

def get_st3_pluginroot():
	usr = getpass.getuser()
	# return '''/Users/%s/Library/Application Support/Sublime Text 3/Packages/User'''%usr
	root = os.path.realpath("/")
	return os.path.join(root, "data0", "public_test")

def install():
	cur_dir = os.getcwd()
	IGNORE_LIST = [
		".git",
		".gitignore"
	]
	copy_dirfiles_to(cur_dir, get_st3_pluginroot(), IGNORE_LIST)

if __name__ == '__main__':
	install()